﻿#include "FITKSpectraAlgorithm.h"
#include <cmath>

namespace Acoustics
{
    FITKSpectraAlgorithm::FITKSpectraAlgorithm(FITKAcousticsAbstractSpectra* spectra) :
        _spectraDataObj(spectra)
    {
        //构造
    }

    FITKSpectraAlgorithm::~FITKSpectraAlgorithm()
    {
        //析构
    }

    void FITKSpectraAlgorithm::setDBAlgConfig(bool dB, double dBValue)
    {
        _dBConfig.first = dB;
        _dBConfig.second = dBValue;
    }

    void FITKSpectraAlgorithm::setAWeighting(bool aWeighting)
    {
        _aWeighting = aWeighting;
    }

    void FITKSpectraAlgorithm::setCalcType(int type)
    {
        _calcType = type;
    }

    bool FITKSpectraAlgorithm::startCalc(bool direction, QList<Acoustics::SpectraValue> spectra)
    {
        if (!_spectraDataObj) return false;
        //设置计算配置参数
        _algDirection = direction;
        if (spectra.isEmpty())
            _spectraData = _spectraDataObj->getSpectraValue();
        else
            _spectraData = spectra;
        //开始计算dB数据
        bool ok = this->calcDBData();
        ok &= this->calcAWeighting();
        ok &= this->calcPSD();
        return ok;
    }

    bool FITKSpectraAlgorithm::calcDBData(bool direction, QList<Acoustics::SpectraValue> spectra)
    {
        if (!_spectraDataObj) return false;
        //设置计算配置参数
        _algDirection = direction;
        if (spectra.isEmpty())
            _spectraData = _spectraDataObj->getSpectraValue();
        else
            _spectraData = spectra;
        //开始计算
        bool ok = this->calcDBData();
        return ok;
    }

    bool FITKSpectraAlgorithm::calcAWeighting(bool direction, QList<Acoustics::SpectraValue> spectra, int rate)
    {
        if (!_spectraDataObj) return false;
        //设置计算配置参数
        _algDirection = direction;
        if (spectra.isEmpty())
            _spectraData = _spectraDataObj->getSpectraValue();
        else
            _spectraData = spectra;
        //开始计算
        bool ok = this->calcAWeighting(rate);
        return ok;
    }

    bool FITKSpectraAlgorithm::calcPSD(bool direction, QList<Acoustics::SpectraValue> spectra)
    {
        if (!_spectraDataObj) return false;
        //设置计算配置参数
        _algDirection = direction;
        if (spectra.isEmpty())
            _spectraData = _spectraDataObj->getSpectraValue();
        else
            _spectraData = spectra;
        //开始计算
        bool ok = this->calcPSD();
        return ok;
    }

    QList<Acoustics::SpectraValue> FITKSpectraAlgorithm::getResults()
    {
        return _spectraData;
    }

    void FITKSpectraAlgorithm::clear()
    {
        _spectraData.clear();
        _dBConfig.first = false;
        _dBConfig.second = 0.0;
        _aWeighting = false;
        _calcType = 0;
        _algDirection = false;
    }

    bool FITKSpectraAlgorithm::calcDBData()
    {
        if (_dBConfig.first == false) return true;
        //获取计算系数
        double coefficient = this->getDBCoefficient();
        double zeroDBPara = _dBConfig.second;
        for (QList<Acoustics::SpectraValue>::iterator iter = _spectraData.begin(); iter != _spectraData.end(); ++iter)
        {
            double value = iter->_value.getReal();
            if (_algDirection)
                value = coefficient * log10(value / zeroDBPara);
            else
                value = zeroDBPara * pow(10, value / coefficient);
            iter->_value.setReal(value);
        }
        return true;
    }

    bool FITKSpectraAlgorithm::calcAWeighting(int rate)
    {
        if (_aWeighting == false) return true;
        /*double aWCoefficient = 0.0;*/
        for (QList<Acoustics::SpectraValue>::iterator iter = _spectraData.begin(); iter != _spectraData.end(); ++iter)
        {
            double hz = this->getAWeightingValue(iter->_hz);
            double value = iter->_value.getReal();
            if (_algDirection)
                value = value + hz * rate /** aWCoefficient*/;
            else
                value = value - hz * rate /** aWCoefficient*/;
            iter->_value.setReal(value);
        }
        return true;
    }

    bool FITKSpectraAlgorithm::calcPSD()
    {
        if (_spectraDataObj == nullptr)return false;
        //判断是否是能量或功率
        bool isEnergyOrPower = false;
        Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType type = _spectraDataObj->getSpectraType();
        if (type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Energy ||
            type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Power) {
            isEnergyOrPower = true;
        }

        if (_calcType == 0) return true;
        for (QList<Acoustics::SpectraValue>::iterator iter = _spectraData.begin(); iter != _spectraData.end(); ++iter)
        {
            double coefficient = this->getPSDConverValue((iter->_hz));
            double value = iter->_value.getReal();
            //正向计算
            if (_algDirection == true) {
                if (_calcType == 1 && type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Energy) {
                    value = value * coefficient;
                }
                else if (_calcType == 1 && type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Power) {
                    value = value * coefficient;
                }
                else if (_calcType == 1) {
                    value = pow(value, 2) / coefficient;
                }
                else if (_calcType == 2 && type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Acceleration) {
                    value = pow(value / 9.8, 2) / coefficient;
                }
                else if (_calcType == 2) {
                    value = value * pow(iter->_hz, 2)*0.4102245;
                }
            }
            //反向计算
            else {
                if (_calcType == 1 && type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Energy) {
                    value = value / coefficient;
                }
                else if (_calcType == 1 && type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Power) {
                    value = value / coefficient;
                }
                else if (_calcType == 1) {
                    value = std::sqrt(value*coefficient);
                }
                else if (_calcType == 2 && type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Acceleration) {
                    value = std::sqrt(value * coefficient)*9.8;
                }
                else if (_calcType == 2) {
                    value = value / pow(iter->_hz, 2) / 0.4102245;
                }
            }
            iter->_value.setReal(value);
        }
        return true;
    }

    double FITKSpectraAlgorithm::getDBCoefficient()
    {
        if (!_spectraDataObj)return 0.0;
        //获取类型
        FITKAcousticsAbstractSpectra::AcousticsSpectraType type = _spectraDataObj->getSpectraType();
        //通过频谱类型获取计算系数
        switch (type)
        {
        case Acoustics::FITKAcousticsAbstractSpectra::None:
            break;
        //同加速度谱算法一致
        case Acoustics::FITKAcousticsAbstractSpectra::Force:
        case Acoustics::FITKAcousticsAbstractSpectra::Moment:
        case Acoustics::FITKAcousticsAbstractSpectra::Pressure:
        case Acoustics::FITKAcousticsAbstractSpectra::Velocity:
        case Acoustics::FITKAcousticsAbstractSpectra::Acceleration:
        case Acoustics::FITKAcousticsAbstractSpectra::AnlrVelocity:
            return _calcType == 0 ? 20.0 : 10.0;
            break;
        //同功率谱算法一致
        case Acoustics::FITKAcousticsAbstractSpectra::Power:
        case Acoustics::FITKAcousticsAbstractSpectra::Energy:
            return 10.0;
            break;
        //同传递损失谱算法一致
        case Acoustics::FITKAcousticsAbstractSpectra::TransmissionLoss:
        case Acoustics::FITKAcousticsAbstractSpectra::InsertionLoss:
            return -10.0;
            break;
        //同模态密度谱算法一致
        case Acoustics::FITKAcousticsAbstractSpectra::ModalDensity:
        case Acoustics::FITKAcousticsAbstractSpectra::Damping:
        case Acoustics::FITKAcousticsAbstractSpectra::Absorption:
        case Acoustics::FITKAcousticsAbstractSpectra::Coupling:
        case Acoustics::FITKAcousticsAbstractSpectra::Wavenumber:
        case Acoustics::FITKAcousticsAbstractSpectra::ShearModulus:
            return 10.0;
            break;
        default:
            break;
        }
        return 0.0;
    }

    double FITKSpectraAlgorithm::getAWeightingValue(double freq)
    {
        double value = 0.0;
        if (freq - 10.0 < 1e-16) value = -70.4;
        else if (freq - 12.5 < 1e-16) value = -63.4;
        else if (freq - 16 < 1e-16) value = -56.7;
        else if (freq - 20 < 1e-16) value = -50.5;
        else if (freq - 25 < 1e-16) value = -44.7;
        else if (freq - 31.5 < 1e-16) value = -39.4;
        else if (freq - 40 < 1e-16) value = -34.6;
        else if (freq - 50 < 1e-16) value = -30.2;
        else if (freq - 63 < 1e-16) value = -26.2;
        else if (freq - 80 < 1e-16) value = -22.5;
        else if (freq - 100 < 1e-16) value = -19.1;
        else if (freq - 125 < 1e-16) value = -16.1;
        else if (freq - 160 < 1e-16) value = -13.4;
        else if (freq - 200 < 1e-16) value = -10.9;
        else if (freq - 250 < 1e-16) value = -8.6;
        else if (freq - 315 < 1e-16) value = -6.6;
        else if (freq - 400 < 1e-16) value = -4.8;
        else if (freq - 500 < 1e-16) value = -3.2;
        else if (freq - 630 < 1e-16) value = -1.9;
        else if (freq - 800 < 1e-16) value = -0.8;
        else if (freq - 1000 < 1e-16) value = 0.0;
        else if (freq - 1250 < 1e-16) value = 0.6;
        else if (freq - 1600 < 1e-16) value = 1.0;
        else if (freq - 2000 < 1e-16) value = 1.2;
        else if (freq - 2500 < 1e-16) value = 1.3;
        else if (freq - 3150 < 1e-16) value = 1.2;
        else if (freq - 4000 < 1e-16) value = 1;
        else if (freq - 5000 < 1e-16) value = 0.5;
        else if (freq - 6300 < 1e-16) value = -0.1;
        else if (freq - 8000 < 1e-16) value = -1.1;
        else if (freq - 10000 < 1e-16) value = -2.5;
        else if (freq - 12500 < 1e-16) value = -4.3;
        else if (freq - 16000 < 1e-16) value = -6.6;
        else if (freq - 20000 < 1e-16) value = -9.3;
        else value = -9.3;
        return value;
    }

    double FITKSpectraAlgorithm::getPSDConverValue(double freq)
    {
        if (_calcType == 0 || !_spectraDataObj)return double();
        double value = 0.0;
        FITKGlobalFrequencyDomain::DomainType type = _spectraDataObj->getDomainType();
        if (type == FITKGlobalFrequencyDomain::DomainType::DTStandardOctave && _calcType == 1)
            value = this->getStandardOctavePSD1Value(freq);
        else if (type == FITKGlobalFrequencyDomain::DomainType::DTStandardOctave && _calcType == 2)
            value = this->getStandardOctavePSD2Value(freq);
        else if (type == FITKGlobalFrequencyDomain::DomainType::DTStandard1Of3rdOctave && _calcType == 1)
            value = this->getStandard1Of3rdOctavePSD1Value(freq);
        else if (type == FITKGlobalFrequencyDomain::DomainType::DTStandard1Of3rdOctave && _calcType == 2)
            value = this->getStandard1Of3rdOctavePSD2Value(freq);
        return value;
    }

    double FITKSpectraAlgorithm::getStandardOctavePSD1Value(double freq)
    {
        if (_spectraDataObj == nullptr)return 0.0;
        Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType type = _spectraDataObj->getSpectraType();
        double value = 0.0;
        if (type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Energy ||
            type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Power) {
            if (freq - 2 < 1e-16) value = 0.5;
            else if (freq - 4 < 1e-16) value = 0.333333;
            else if (freq - 8 < 1e-16) value = 0.2;
            else if (freq - 16 < 1e-16) value = 0.0909091;
            else if (freq - 31.5 < 1e-16) value = 0.0454545;
            else if (freq - 63 < 1e-16) value = 0.0227273;
            else if (freq - 125 < 1e-16) value = 0.011236;
            else if (freq - 250 < 1e-16) value = 0.00561798;
            else if (freq - 500 < 1e-16) value = 0.0028169;
            else if (freq - 1000 < 1e-16) value = 0.00140845;
            else if (freq - 2000 < 1e-16) value = 0.000704225;
            else if (freq - 4000 < 1e-16) value = 0.000352113;
            else if (freq - 8000 < 1e-16) value = 0.000176056;
            else if (freq - 16000 < 1e-16) value = 8.80282e-005;
            else if (freq - 32000 < 1e-16) value = 4.43757e-005;
            else if (freq - 64000 < 1e-16) value = 2.20971e-005;
            else if (freq - 128000 < 1e-16) value = 1.10485e-005;
        }
        else {
            if (freq - 2 < 1e-16) value = 2;
            else if (freq - 4 < 1e-16) value = 3;
            else if (freq - 8 < 1e-16) value = 5;
            else if (freq - 16 < 1e-16) value = 11;
            else if (freq - 31.5 < 1e-16) value = 22;
            else if (freq - 63 < 1e-16) value = 44.0001;
            else if (freq - 125 < 1e-16) value = 88.99964;
            else if (freq - 250 < 1e-16) value = 178;
            else if (freq - 500 < 1e-16) value = 355.0002;
            else if (freq - 1000 < 1e-16) value = 709.9976;
            else if (freq - 2000 < 1e-16) value = 1420;
            else if (freq - 4000 < 1e-16) value = 2840.004;
            else if (freq - 8000 < 1e-16) value = 5679.989;
            else if (freq - 16000 < 1e-16) value = 11359.99;
            else if (freq - 32000 < 1e-16) value = 22534.82;
            else if (freq - 64000 < 1e-16) value = 45254.78;
            else if (freq - 128000 < 1e-16) value = 90509.66;
        }

        return value;
    }

    double FITKSpectraAlgorithm::getStandardOctavePSD2Value(double freq)
    {
        double value = 0.0;
        if (freq - 2 < 1e-16) value = 2;
        else if (freq - 4 < 1e-16) value = 3;
        else if (freq - 8 < 1e-16) value = 5;
        else if (freq - 16 < 1e-16) value = 11;
        else if (freq - 31.5 < 1e-16) value = 22;
        else if (freq - 63 < 1e-16) value = 44.0001;
        else if (freq - 125 < 1e-16) value = 88.9996;
        else if (freq - 250 < 1e-16) value = 128;
        else if (freq - 500 < 1e-16) value = 355.0002;
        else if (freq - 1000 < 1e-16) value = 709.9976;
        else if (freq - 2000 < 1e-16) value = 1420;
        else if (freq - 4000 < 1e-16) value = 2840.004;
        else if (freq - 8000 < 1e-16) value = 5679.989;
        else if (freq - 16000 < 1e-16) value = 11359.99;
        else if (freq - 32000 < 1e-16) value = 22534.82;
        else if (freq - 64000 < 1e-16) value = 45254.78;
        else if (freq - 128000 < 1e-16) value = 90509.66;
        return value;
    }

    double FITKSpectraAlgorithm::getStandard1Of3rdOctavePSD1Value(double freq)
    {
        if (_spectraDataObj == nullptr)return 0.0;
        Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType type = _spectraDataObj->getSpectraType();
        double value = 0.0;
        if (type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Energy ||
            type == Acoustics::FITKAcousticsAbstractSpectra::AcousticsSpectraType::Power) {
            if (freq - 1.25 < 1e-16) value = 3.57143;
            else if (freq - 1.6 < 1e-16) value = 2.5;
            else if (freq - 2 < 1e-16) value = 2.272725;
            else if (freq - 2.5 < 1e-16) value = 1.78571;
            else if (freq - 3.15 < 1e-16) value = 1.33333;
            else if (freq - 4 < 1e-16) value = 1.05263;
            else if (freq - 5 < 1e-16) value = 0.909091;
            else if (freq - 6.3 < 1e-16) value = 0.666667;
            else if (freq - 8 < 1e-16) value = 0.526316;
            else if (freq - 10 < 1e-16) value = 0.454546;
            else if (freq - 12.5 < 1e-16) value = 0.344827;
            else if (freq - 16 < 1e-16) value = 0.27027;
            else if (freq - 20 < 1e-16) value = 0.217391;
            else if (freq - 25 < 1e-16) value = 0.172414;
            else if (freq - 31.5 < 1e-16) value = 0.136986;
            else if (freq - 40 < 1e-16) value = 0.108696;
            else if (freq - 50 < 1e-16) value = 0.0869565;
            else if (freq - 63 < 1e-16) value = 0.0684931;
            else if (freq - 80 < 1e-16) value = 0.0546448;
            else if (freq - 100 < 1e-16) value = 0.0436681;
            else if (freq - 125 < 1e-16) value = 0.0344828;
            else if (freq - 160 < 1e-16) value = 0.027027;
            else if (freq - 200 < 1e-16) value = 0.0217391;
            else if (freq - 250 < 1e-16) value = 0.0172414;
            else if (freq - 315 < 1e-16) value = 0.0136986;
            else if (freq - 400 < 1e-16) value = 0.0108696;
            else if (freq - 500 < 1e-16) value = 0.00869565;
            else if (freq - 630 < 1e-16) value = 0.00684932;
            else if (freq - 800 < 1e-16) value = 0.00546448;
            else if (freq - 1000 < 1e-16) value = 0.004329;
            else if (freq - 1250 < 1e-16) value = 0.00343643;
            else if (freq - 1600 < 1e-16) value = 0.00273973;
            else if (freq - 2000 < 1e-16) value = 0.0021692;
            else if (freq - 2500 < 1e-16) value = 0.00172712;
            else if (freq - 3150 < 1e-16) value = 0.00136986;
            else if (freq - 4000 < 1e-16) value = 0.00108814;
            else if (freq - 5000 < 1e-16) value = 0.000865052;
            else if (freq - 6300 < 1e-16) value = 0.000686813;
            else if (freq - 8000 < 1e-16) value = 0.000545256;
            else if (freq - 10000 < 1e-16) value = 0.000433463;
            else if (freq - 12500 < 1e-16) value = 0.000343643;
            else if (freq - 16000 < 1e-16) value = 0.000273973;
            else if (freq - 20000 < 1e-16) value = 0.00021692;
            else if (freq - 25000 < 1e-16) value = 0.000176319;
            else if (freq - 32000 < 1e-16) value = 0.000127271;
            else if (freq - 40000 < 1e-16) value = 0.000111362;
            else if (freq - 50000 < 1e-16) value = 8.90899e-005;
            else if (freq - 64000 < 1e-16) value = 6.36356e-005;
            else if (freq - 80000 < 1e-16) value = 5.56812e-005;
            else if (freq - 100000 < 1e-16) value = 4.45449e-005;
            else if (freq - 128000 < 1e-16) value = 3.18178e-005;
            else if (freq - 160000 < 1e-16) value = 2.78406e-005;
        }
        else {
            if (freq - 1.25 < 1e-16) value = 0.279999790000158;
            else if (freq - 1.6 < 1e-16) value = 0.4;
            else if (freq - 2 < 1e-16) value = 0.44000044000044;
            else if (freq - 2.5 < 1e-16) value = 0.56000056000056;
            else if (freq - 3.15 < 1e-16) value = 0.750001171876831;
            else if (freq - 4 < 1e-16) value = 0.950000296875093;
            else if (freq - 5 < 1e-16) value = 1.09999656251074;
            else if (freq - 6.3 < 1e-16) value = 1.49999531251465;
            else if (freq - 8 < 1e-16) value = 1.90000059375019;
            else if (freq - 10 < 1e-16) value = 2.19999917500031;
            else if (freq - 12.5 < 1e-16) value = 2.90000072500018;
            else if (freq - 16 < 1e-16) value = 3.69999514375637;
            else if (freq - 20 < 1e-16) value = 4.60000115000029;
            else if (freq - 25 < 1e-16) value = 5.80000145000036;
            else if (freq - 31.5 < 1e-16) value = 7.30000273750103;
            else if (freq - 40 < 1e-16) value = 9.20000230000058;
            else if (freq - 50 < 1e-16) value = 11.5000359376123;
            else if (freq - 63 < 1e-16) value = 14.6000054750021;
            else if (freq - 80 < 1e-16) value = 18.2999987418751;
            else if (freq - 100 < 1e-16) value = 22.8999985687501;
            else if (freq - 125 < 1e-16) value = 29.0000072500018;
            else if (freq - 160 < 1e-16) value = 37.000037000037;
            else if (freq - 200 < 1e-16) value = 46.0000115000029;
            else if (freq - 250 < 1e-16) value = 58.0000145000036;
            else if (freq - 315 < 1e-16) value = 73.0000273750103;
            else if (freq - 400 < 1e-16) value = 92.0000230000057;
            else if (freq - 500 < 1e-16) value = 115.000359376123;
            else if (freq - 630 < 1e-16) value = 146.000054750021;
            else if (freq - 800 < 1e-16) value = 182.999987418751;
            else if (freq - 1000 < 1e-16) value = 230.999897493795;
            else if (freq - 1250 < 1e-16) value = 291.000094575031;
            else if (freq - 1600 < 1e-16) value = 365.000136875051;
            else if (freq - 2000 < 1e-16) value = 460.999446800664;
            else if (freq - 2500 < 1e-16) value = 578.998983133036;
            else if (freq - 3150 < 1e-16) value = 730.000273750103;
            else if (freq - 4000 < 1e-16) value = 919.001504864964;
            else if (freq - 5000 < 1e-16) value = 1156.00254320559;
            else if (freq - 6300 < 1e-16) value = 1456.00145600146;
            else if (freq - 8000 < 1e-16) value = 1834.000068775;
            else if (freq - 10000 < 1e-16) value = 2306.997990028;
            else if (freq - 12500 < 1e-16) value = 2910.00094575031;
            else if (freq - 16000 < 1e-16) value = 3650.00136875051;
            else if (freq - 20000 < 1e-16) value = 4609.99446800664;
            else if (freq - 25000 < 1e-16) value = 5671.54655985254;
            else if (freq - 32000 < 1e-16) value = 7857.23405718102;
            else if (freq - 40000 < 1e-16) value = 8979.68346615782;
            else if (freq - 50000 < 1e-16) value = 11224.6043326973;
            else if (freq - 64000 < 1e-16) value = 15714.468114362;
            else if (freq - 80000 < 1e-16) value = 17959.3870910171;
            else if (freq - 100000 < 1e-16) value = 22449.2401633743;
            else if (freq - 128000 < 1e-16) value = 31428.9362287241;
            else if (freq - 160000 < 1e-16) value = 35918.7338646313;
        }
        return value;
    }

    double FITKSpectraAlgorithm::getStandard1Of3rdOctavePSD2Value(double freq)
    {
        double value = 0.0;
        if (freq - 1.25 < 1e-16) value = 0.279999790000158;
        else if (freq - 1.6 < 1e-16) value = 0.4;
        else if (freq - 2 < 1e-16) value = 0.44000044000044;
        else if (freq - 2.5 < 1e-16) value = 0.56000056000056;
        else if (freq - 3.15 < 1e-16) value = 0.750001171876831;
        else if (freq - 4 < 1e-16) value = 0.950000296875093;
        else if (freq - 5 < 1e-16) value = 1.09999656251074;
        else if (freq - 6.3 < 1e-16) value = 1.49999531251465;
        else if (freq - 8 < 1e-16) value = 1.90000059375019;
        else if (freq - 10 < 1e-16) value = 2.19999917500031;
        else if (freq - 12.5 < 1e-16) value = 2.90000072500018;
        else if (freq - 16 < 1e-16) value = 3.69999514375637;
        else if (freq - 20 < 1e-16) value = 4.60000115000029;
        else if (freq - 25 < 1e-16) value = 5.80000145000036;
        else if (freq - 31.5 < 1e-16) value = 7.30000273750103;
        else if (freq - 40 < 1e-16) value = 9.20000230000058;
        else if (freq - 50 < 1e-16) value = 11.5000359376123;
        else if (freq - 63 < 1e-16) value = 14.6000054750021;
        else if (freq - 80 < 1e-16) value = 18.2999987418751;
        else if (freq - 100 < 1e-16) value = 22.8999985687501;
        else if (freq - 125 < 1e-16) value = 29.0000072500018;
        else if (freq - 160 < 1e-16) value = 37.000037000037;
        else if (freq - 200 < 1e-16) value = 46.0000115000029;
        else if (freq - 250 < 1e-16) value = 58.0000145000036;
        else if (freq - 315 < 1e-16) value = 73.0000273750103;
        else if (freq - 400 < 1e-16) value = 92.0000230000057;
        else if (freq - 500 < 1e-16) value = 115.000359376123;
        else if (freq - 630 < 1e-16) value = 146.000054750021;
        else if (freq - 800 < 1e-16) value = 182.999987418751;
        else if (freq - 1000 < 1e-16) value = 230.999897493795;
        else if (freq - 1250 < 1e-16) value = 291.000094575031;
        else if (freq - 1600 < 1e-16) value = 365.000136875051;
        else if (freq - 2000 < 1e-16) value = 460.999446800664;
        else if (freq - 2500 < 1e-16) value = 578.998983133036;
        else if (freq - 3150 < 1e-16) value = 730.000273750103;
        else if (freq - 4000 < 1e-16) value = 919.001504864964;
        else if (freq - 5000 < 1e-16) value = 1156.00254320559;
        else if (freq - 6300 < 1e-16) value = 1456.00145600146;
        else if (freq - 8000 < 1e-16) value = 1834.000068775;
        else if (freq - 10000 < 1e-16) value = 2306.997990028;
        else if (freq - 12500 < 1e-16) value = 2910.00094575031;
        else if (freq - 16000 < 1e-16) value = 3650.00136875051;
        else if (freq - 20000 < 1e-16) value = 4609.99446800664;
        else if (freq - 25000 < 1e-16) value = 5671.54655985254;
        else if (freq - 32000 < 1e-16) value = 7857.23405718102;
        else if (freq - 40000 < 1e-16) value = 8979.68346615782;
        else if (freq - 50000 < 1e-16) value = 11224.6043326973;
        else if (freq - 64000 < 1e-16) value = 15714.468114362;
        else if (freq - 80000 < 1e-16) value = 17959.3870910171;
        else if (freq - 100000 < 1e-16) value = 22449.2401633743;
        else if (freq - 128000 < 1e-16) value = 31428.9362287241;
        else if (freq - 160000 < 1e-16) value = 35918.7338646313;
        return value;
    }
}
